package bot.conf;

import bot.mapper.*;
import bot.pojo.EnemyTable;
import bot.pojo.EnemyTableExample;
import bot.pojo.PropTable;
import bot.pojo.PropTableExample;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

@Data
@Component
//初始化Mapper
public class MpperUnit {
    /**
     * 不要和类名一致，否则打成jar文件会为null
     * */
    public static MpperUnit staticmpperUnit;
    //mapper...
    @Autowired
    private MiUserTableMapper miUserTableMapper;
    @Autowired
    private GameUserTableMapper gameUserTableMapper;
    @Autowired
    private GameTableMapper gameTableMapper;
    @Autowired
    private CharacterToUserMapper characterToUserMapper;
    @Autowired
    private PropTableMapper propTableMapper;
    @Autowired
    private PropToUserMapper propToUserMapper;
    private PropTableExample propTableExample = new PropTableExample();
    @Autowired
    private CharacterTableMapper characterTableMapper;
    @Autowired
    private EnemyTableMapper enemyTableMapper;


    private List<PropTable> propTableList = new ArrayList<>();
    private List<EnemyTable> enemyTables = new ArrayList<>();
    @PostConstruct
    public void init(){
        System.out.println("----Mapper初始化----");
        staticmpperUnit = this;
        staticmpperUnit.miUserTableMapper = this.miUserTableMapper;
        staticmpperUnit.gameUserTableMapper = this.gameUserTableMapper;
        staticmpperUnit.gameTableMapper = this.gameTableMapper;
        staticmpperUnit.characterToUserMapper = this.characterToUserMapper;
        staticmpperUnit.propTableMapper = this.propTableMapper;
        staticmpperUnit.propToUserMapper = this.propToUserMapper;
        staticmpperUnit.enemyTableMapper = this.enemyTableMapper;
        staticmpperUnit.characterTableMapper = this.characterTableMapper;
        System.out.println("----加载初始数据----");
        //加载道具列表
        //加载道具
        propTableList = propTableMapper.selectByExample(propTableExample);
        System.out.println("道具列表数量:" + propTableList.size());
        //加载敌人
        enemyTables = enemyTableMapper.selectByExample(new EnemyTableExample());
        System.out.println("敌人数量:"+enemyTables.size());
        try{

        }catch (Exception e){

        }
    }
}
